local tuanzhang_active = fk.CreateSkill {
  name = "cf_tuanzhang_active&",
}

Fk:loadTranslationTable {
  ["cf_tuanzhang_active&"] = "团长",
  [":cf_tuanzhang_active&"] = "出牌阶段限一次，你可以交给琴一张牌，然后获得一项效果",
  ["#cf_tuanzhang_active&"] = "选择一张牌交出",
  ["cf_tuanzhang_chioce1"] = "令其从牌堆顶和牌堆底各摸一张牌。",
  ["cf_tuanzhang_chioce2"] = "令其回复一点体力。",
  ["cf_tuanzhang_chioce3"] = "令其下次造成伤害翻倍。",
  ["@@cf_tuanzhang_active&"] = "下次伤害翻倍",
  ["$cf_tuanzhang_active&1"] = "希望大家都能获得宝藏。",
  ["$cf_tuanzhang_active&2"] = "骑士团的大家，有没有认真工作呢。",
}

tuanzhang_active:addEffect("active", {
  prompt = "#cf_tuanzhang_active&",
  card_num = 1,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and player.kingdom == "Mondstadt" and
        not player:isKongcheng() and
        table.find(Fk:currentRoom().alive_players, function(p)
          return p:hasSkill("cf_tuanzhang") and p ~= player
        end)
  end,
  card_filter = function(self, player, to_select, selected, selected_targets)
    return #selected == 0
  end,
  on_use = function(self, room, skillUseEvent)
    local player = skillUseEvent.from
    local targets = table.filter(room.alive_players, function(p)
      return p:hasSkill("cf_tuanzhang") and p ~= player
    end)
    local target
    if #targets == 1 then
      target = targets[1]
    else
      target = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = "cf_tuanzhang",
        cancelable = false,
      })[1]
    end
    if not target then return end
    room:obtainCard(target, skillUseEvent.cards, false, fk.ReasonJustMove, target, "cf_tuanzhang")
    local choice = room:askToChoice(target, {
      choices = { "cf_tuanzhang_chioce1", "cf_tuanzhang_chioce2", "cf_tuanzhang_chioce3" },
      skill_name = "cf_tuanzhang",
    })
    if choice == "cf_tuanzhang_chioce1" then
      player:drawCards(1, "cf_tuanzhang", "top")
      player:drawCards(1, "cf_tuanzhang", "bottom")
    elseif choice == "cf_tuanzhang_chioce2" then
      room:recover {
        who = player,
        skillName = self.name,
        num = 1
      }
    elseif choice == "cf_tuanzhang_chioce3" then
      room:addPlayerMark(player, "@@cf_tuanzhang_active&")
    end
  end
})

tuanzhang_active:addEffect(fk.DamageCaused, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@@cf_tuanzhang_active&") ~= 0 and player == data.from
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.damage = 2 ^ player:getMark("@@cf_tuanzhang_active&") * data.damage
    room:setPlayerMark(player, "@@cf_tuanzhang_active&", 0)
  end
})

return tuanzhang_active
